package com.one.common.config;


import com.google.gson.Gson;
import com.one.common.model.bean.UserInfoBean;
import com.one.common.utils.Logger;
import com.one.common.utils.StringUtils;

/**
 *
 * Author：zhulunjun
 * Time：2017/9/16
 * description： 内存数据
 */

public class CMemoryData {
    /**
     * 用户信息
     */
    private static UserInfoBean userInfo;


    public static UserInfoBean getUserInfo() {
        if(userInfo == null){
            String info = CPersisData.getUserInfo();
            if(StringUtils.isNotBlank(info)){
                userInfo = new Gson().fromJson(info, UserInfoBean.class);
            }
        }
        if(userInfo == null){
            userInfo = new UserInfoBean();
        } else {
            Logger.d("用户信息 "+userInfo.toString());
        }
        return userInfo;
    }

    public static void setUserInfo(UserInfoBean userInfo) {
        if(userInfo != null){
            String infoJson = new Gson().toJson(userInfo);
            if(StringUtils.isNotBlank(infoJson)){
                CPersisData.setUserInfo(infoJson);
            }
        }
        CMemoryData.userInfo = userInfo;
    }
}
